//
//  HomeView.swift
//  WeiboDemo
//
//  Created by 姬向阳 on 2020/4/19.
//  Copyright © 2020 SUNNYJ. All rights reserved.
//

import SwiftUI

struct HomeView: View {
    @State var leftPercent : CGFloat = 0
    
    init() { // 设置样式
        // 去掉UITableView里面自带的一根分割线
        UITableView.appearance().separatorStyle = .none
        // 取消UITableViewCell的点击样式,点击不会变灰
        UITableViewCell.appearance().selectionStyle = .none
    }
    
    var body: some View {
        NavigationView {
            GeometryReader{ geometry in
                HScrollViewController(pageWidth: geometry.size.width,
                                      contentSize: CGSize(width: geometry.size.width * 2, height: geometry.size.height),
                                      leftPercent: self.$leftPercent) {
                    HStack {
                        PostListView(category: .recommend)
                            .frame(width: UIScreen.main.bounds.width)
                        PostListView(category: .hot)
                            .frame(width: UIScreen.main.bounds.width)
                    }
                }
            }
            //.edgesIgnoringSafeArea(.bottom)
            .navigationBarItems(leading: HomeNavigationBar(leftPercent: $leftPercent))
            .navigationBarTitle("首页",displayMode: .inline)
        }
        .navigationViewStyle(StackNavigationViewStyle()) // 使得iPad与iPhone样式一样
    }
}

struct HomeView_Previews: PreviewProvider {
    static var previews: some View {
        HomeView().environmentObject(UserData())
    }
}
